package com.sx.micowell.framework.binding.adapter.smartrefresh

import androidx.databinding.BindingAdapter
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.sx.micowell.framework.binding.BindingCommand

/**
 * @Author: YY
 * @Time: 2021/8/19
 * @Describe TODO
 */
object ViewAdapter {

    @JvmStatic
    @BindingAdapter("onRefreshCommand")
    fun onRefreshCommand(smartRefreshLayout: SmartRefreshLayout, onRefreshCommand: BindingCommand<*>?) {
        smartRefreshLayout.setOnRefreshListener {
                refreshLayout: RefreshLayout? -> onRefreshCommand?.executeAction()
        }
    }

    @JvmStatic
    @BindingAdapter("onLoadMoreCommand")
    fun onLoadMoreCommand(smartRefreshLayout: SmartRefreshLayout, onLoadCommand: BindingCommand<*>?) {
        smartRefreshLayout.setOnLoadMoreListener { refreshLayout: RefreshLayout? -> onLoadCommand?.executeAction() }
    }
}